import { InboxOutlined } from '@ant-design/icons';
import type { UploadProps } from 'antd';
import { message, Upload } from 'antd';

const { Dragger } = Upload;

const App = ({
  setModifyFile
}: any) => {
  const props: UploadProps = {
    name: 'file',
    multiple: true,
    onChange(info) {
      const { status } = info.file;
      if (status !== 'uploading') {
        setModifyFile(info.fileList)
      }
      if (status === 'done') {
        message.success('上传成功');
      }
    },
    onDrop(e) {
      console.log('Dropped files', e.dataTransfer.files);
    },
    customRequest(options: any) {
      options.onSuccess(true)
    },
    onPreview(e) {
      console.log(e);
      if (e?.originFileObj?.path) {
        window.api.operationWindow('openPath', { url: e?.originFileObj?.path })
      }
    }
  };
  
  return (
    <Dragger {...props}>
      <p className="ant-upload-drag-icon">
        <InboxOutlined />
      </p>
      <p className="ant-upload-text">
        点击或拖拽来上传修改的文件
      </p>
    </Dragger>
  )
};

export default App;